(function ($, window, document, undefined) {
    'use strict';

    var $form = $('#withdraw-form');

    $form.submit(function (e) {
        // remove the error class
        $('.form-group').removeClass('has-error');
        $('.help-block').remove();

        // get the form data
        var formData = {
            'address' : $('input[name="form-address"]').val(),
            'count' : $('input[name="form-count"]').val()
        };

        // process the form
        $.ajax({
            type : 'POST',
            url  : '/account/apply/withdraw',
            data : formData,
            contentType:'application/json',
            encode : true
        }).done(function (data) {
            window.location.href = "/account/earn/list?openid="+$('input[id="openid"]').val();
        }).fail(function (data) {
            // for debug
            console.log(data)
        });

        e.preventDefault();
    });
}(jQuery, window, document));
